/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package acceso.util;

import acceso.servicio.Service_manager;
import acceso.servicio.Servicio;
import acceso.servicio.correo.SCorreo;
import acceso.servicio.twitter.STwitter;
//import akka.actor.UntypedActor;
import java.io.File;
import java.util.ArrayList;
import java.util.List;
import javax.xml.parsers.DocumentBuilder;
import javax.xml.parsers.DocumentBuilderFactory;

import org.w3c.dom.Document;
import org.w3c.dom.Element;
import org.w3c.dom.Node;
import org.w3c.dom.NodeList;
//import scala.actors.Actor;

/**
 *
 * @author romulogalindo
 */
public class Rankana /*extends UntypedActor*/ {

    Document doc;
    Element wfi;

    public void zuz() {
        Servicio ser_correo = new SCorreo(null);
        ser_correo.iniciar();
    }

    public void zuz2() {
        Servicio ser_correo = new SCorreo(null);
        ser_correo.iniciar();
    }

    public void procesar() {
        List ls = new ArrayList();
        ls.add(new SCorreo(null));
        ls.add(new STwitter(null));
        Service_manager.add_servicio(ls);
        Service_manager.get_servicio(0).iniciar();
        Service_manager.get_servicio(1).iniciar();
        
        Service_manager.get_servicio(0).detener();
        Service_manager.get_servicio(1).detener();
        
   }

    public void procesar2() {
        DocumentBuilderFactory FACTORY = null;
        DocumentBuilder BUILDER = null;
        Document DOCUMENT = null;

        try {
            FACTORY = DocumentBuilderFactory.newInstance();
            BUILDER = FACTORY.newDocumentBuilder();
            //Registro02_211212
            //DOCUMENT = BUILDER.parse(new File("/home/romulogalindo/DOIT/Registro02_19122012.xml"));
            //DOCUMENT = BUILDER.parse(new File("/home/romulogalindo/DOIT/Registro02_211212.xml"));

            //DOCUMENT = BUILDER.parse(new File("/home/romulogalindo/DOIT/Registro02_26122012.xml"));

//            DOCUMENT = BUILDER.parse(new File("/home/romulogalindo/Descargas/Registro02MeryPilar16-04.xml"));
            DOCUMENT = BUILDER.parse(new File("/home/romulogalindo/Descargas/Registro02.xml"));

            System.out.println("RANKAN:>>>");
            System.out.println(">5");
        } catch (Exception ep) {
            System.out.println(">" + ep.getMessage());
        }


        DOCUMENT.getDocumentElement().normalize();
        wfi = DOCUMENT.getDocumentElement();
        NodeList charts = wfi.getElementsByTagName("Registro");
        System.out.println("charts.getLength():" + charts.getLength());

        System.out.println("");

        String row = "";

        for (int i = 0; i < charts.getLength(); i++) {
            Node node = charts.item(i);
            NodeList OP = node.getChildNodes();

            //System.out.println("NAME:" + node.getNodeName());
            for (int o = 0; o < OP.getLength(); o++) {
                Node RV = OP.item(o);
                if (!RV.getNodeName().contentEquals("#text")) {
                    NodeList nodo2 = RV.getChildNodes();
                    String valor = "";
                    try {
                        valor = nodo2.item(0).getNodeValue();
                    } catch (Exception ep) {
                        valor = "";
                    }

                    row = row + valor + ",";
                }
            }
            System.out.println("" + (i + 1) + "," + row.substring(0, row.length() - 1));
            //System.out.println("\n\n");
            row = "";
            //System.out.println("VALUE:"+node.getTextContent());

        }



    }

    public static void main(String[] args) {
        /*DocumentBuilderFactory FACTORY = null;
         DocumentBuilder BUILDER = null;
         Document DOCUMENT = null;*/
        try {
            /*FACTORY = DocumentBuilderFactory.newInstance();
             BUILDER = FACTORY.newDocumentBuilder();
             DOCUMENT = BUILDER.parse(new File("/home/romulogalindo/DOIT/Registro02_19122012.xml"));*/
            Rankana r = new Rankana();
//            r.procesar();
            r.procesar2();

            //System.out.println("RANKAN:>>>");
            //System.out.println(">5");
        } catch (Exception ep) {
            System.out.println(">" + ep.getMessage());
        }
    }
    /*
     @Override
     public void onReceive(Object o) throws Exception {
        
     }*/
}
